home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-08 | 3.0 KB | 143 lines | [TEXT/CWIE] |
- //Copyright (c) 1997 Aidan Cully
- //All rights reserved
-
- #include "DocContent.h"
- #include "MenuHandler.h"
- #include <Scrap.h>
- #include <Drag.h>
- #include "CLApplication.h"
- #include "Messages.h"
-
- TDocContent::TDocContent( TLayoutBranch *super, Boolean hasDD, MActionHandler *superHandler, TPlane *plane ):
- TLayoutLeaf( super ),
- MActionHandler( superHandler ),
- mPlane( plane ),
- mHasDragDrop( hasDD )
- {
- mPlane->AddReceiver( this );
- }
-
- Boolean TDocContent::Init()
- {
- TLayoutLeaf::Init();
- }
-
- Boolean TDocContent::MakeActive( Boolean active )
- {
- Boolean retVal= TLayoutLeaf::MakeActive( active );
- if( retVal && active )
- MakeActive();
- return( retVal );
- }
-
- SInt8 TDocContent::MakeActive()
- {
- return( MActionHandler::MakeActive() );
- }
-
- SInt8 TDocContent::HandleAction( UInt32 message )
- {
- UInt16 menu, item;
-
- menu= message>>16;
- item= message&0x00ff;
- switch( menu ) {
- case m_EDIT:
- switch( item ) {
- case me_COPY:
- CopySelf();
- break;
- }
- break;
- }
- if( mSuperHandler )
- return( mSuperHandler->HandleAction( message ) );
- return( 1 );
- }
-
- TPicture *TDocContent::GetPicture()
- {
- TPicture *picture;
- picture= new TPicture( GetLocalRect() );
- Draw( picture );
- return( picture );
- }
-
- void TDocContent::CopySelf()
- {
- TPicture *picture;
- PicHandle image;
-
- ::ZeroScrap();
- picture= GetPicture();
- image= picture->GetPic();
- MoveHHi( (Handle)image );
- HLock( (Handle)image );
- PutScrap( GetHandleSize( (Handle)image ), 'PICT', *image );
- HUnlock( (Handle)image );
- delete picture;
- }
-
- Rect TDocContent::GetLargestSize()
- {
- Rect largRect;
- ::SetRect( &largRect, 0, 0, 32700, 32700 );
- return( largRect );
- }
-
- int TDocContent::ReceiveMessage( TMessage *msg )
- {
- switch( msg->mWhat ) {
- case kUpdateWindow:
- Draw( mWindow );
- return( 1 );
- default:
- return( 0 );
- }
- return( 1 );
- }
-
- Boolean TDocContent::HandleMouseSelf( TMouseButtonEvent *ev )
- {
- if( !mHasDragDrop )
- return( true );
- if( ::WaitMouseMoved( ev->where ) ) {
- GWorldPtr oldWorld;
- GDHandle oldDevice;
- ::GetGWorld( &oldWorld, &oldDevice );
- GWorldPtr newWorld;
- GDHandle newDevice;
- TApplication::SCurApp()->GetGlobalWorld( newWorld, newDevice );
- ::SetGWorld( newWorld, newDevice );
- DragReference drag;
- ::NewDrag( &drag );
- RgnHandle dragRgn= ::NewRgn(), inRgn= ::NewRgn();
- ::RectRgn( dragRgn, &mContentRect );
- ::CopyRgn( dragRgn, inRgn );
- ::InsetRgn( inRgn, 1, 1 );
- ::DiffRgn( dragRgn, inRgn, dragRgn );
- ::DisposeRgn( inRgn );
- Point pt;
- pt.h= 0; pt.v= 0;
- mWindow->LocalToGlobal( &pt );
- ::OffsetRgn( dragRgn, pt.h, pt.v );
- TPicture *picture= GetPicture();
- PicHandle image= picture->GetPic();
- ::HLock( (Handle)image );
- ::AddDragItemFlavor( drag, 1, 'PICT', *image, ::GetHandleSize( (Handle)image ), 0 );
- ::HUnlock( (Handle)image );
- EventRecord myEv;
- myEv.where= ev->where;
- mWindow->LocalToGlobal( &myEv.where );
- ::TrackDrag( drag, &myEv, dragRgn );
- ::DisposeDrag( drag );
- ::DisposeRgn( dragRgn );
- ::PenPat( &qd.black );
- RGBColor black;
- black.red= 0; black.green= 0; black.blue= 0;
- ::RGBForeColor( &black );
- ::SetGWorld( oldWorld, oldDevice );
- delete picture;
- }
- return( true );
- }